﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "Common.h"
#include "ExpressionParser.h"

#pragma execution_character_set("utf-8")

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QStringList options;
    options << "工程格式" << "整数" << "浮点" << "固定点" << "科学式" << "未格式化";
    ui->comboBox->addItems(options);
    connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_comboBoxcurrentIndexChanged(int)));
    connect(ui->lineEdit_3, SIGNAL(textChanged(const QString&)), this, SLOT(onEdit3TextChanged(const QString&)));
    connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(onPushButtonclicked()));
}

void MainWindow::onPushButtonclicked()
{
    m_strExpressValue = ui->lineEdit_3->text();
    ItemView data = ExpressionParser::parseExpression(m_strExpressValue);
    data.value = 3.141592654;
    QString strAAA = ExpressionParser::formatDisplayText(data);
    // bool bRet = ExpressionParser::updateExpression();
    ui->lineEdit->setText(strAAA);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_comboBoxcurrentIndexChanged(int index)
{
   // options << "工程格式" << "整数" << "浮点" << "固定点" << "科学式" << "未格式化";
   ItemView data = ExpressionParser::parseExpression(m_strExpressValue);
   data.value = 3.141592654;
   QString strAAA = ExpressionParser::formatDisplayText(data);

   ui->lineEdit->setText(strAAA);
}

void MainWindow::onEdit3TextChanged(const QString &str)
{
    m_strExpressValue = ui->lineEdit_3->text();
}